using System;
using System.ComponentModel;
using System.Windows.Input;
using WpfLob.Commands;

namespace WpfLob.Frame
{
    public abstract class Pane : INotifyPropertyChanged
    {
        private IPresenter _presenter;

        public Pane(IPresenter presenter)
        {
            _presenter = presenter;

            _presenter.PropertyChanged += PresenterPropertyChanged;
        }

        void PresenterPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "CurrentPaneIndex")
                FirePropertyChanged("Position");
        }
        
        protected IPresenter Presenter
        {
            get { return _presenter; }
        }

        public PanePosition Position
        {
            get { return _presenter.PositionOf(this); }
        }

        public abstract string Title { get; }

        public ICommand GoBack
        {
            get
            {
                return new SimpleCommand(() => Presenter.GoBackTo(this));
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void FirePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion
    }
}
